window.DwManager = {
		
	HTTP_CODE : {
		AUTHORITY_ERROR : 401,

		BAD_REQUEST : 400
	},
	
	renderTemplet : function(templet, args) {
		if (!templet || !args) {
			return;
		}
		for (var name in args) {
			var regx = new RegExp("\\$" + name, "g");
			templet = templet.replace(regx, args[name]);
		}
		return templet;
	},
	
	clickOpenAndClose : function($target, $openButton, $closeButton) {
		$openButton.click(function() {
			$target.moveShowAndHide({
				direct : "show",
				top : 0
			});
		});
		
		$closeButton.click(function() {
			$target.moveShowAndHide({
				direct : "hide",
				top : -60
			});
		});
	},
	
	renderTurnPage : function(config) {
		var $target = config.target,
			queryparams = config.query,
			url = config.url,
			currentPage = config.currentPage,
			totalPage = config.totalPage
		var $form = $("<form>").attr({
			action : url
		});
		for (var name in queryparams) {
			var $input = $('<input type="hidden" >');
			$input.attr({
				name : name,
				value : queryparams[name]
			});
			$form.append($input);
		}
		$select = $("<select>").attr({name : "currentPage"}).appendTo($form).change(function() {
			$form.submit();
		});
		for (var i = 1, ii = totalPage; i <= ii; i++) {
			var $option = $("<option>").attr({value : i}).text("第" + i + "页").appendTo($select);
			if (currentPage == i) {
				$option.attr({selected : "selected"});
			}
		}
		$target.append($form);
	},
	
	
	resizeWindow : function() {
		var me = this;
		//iframe onload && window.resize excute 
		$("#iframe-zone").get(0).onload = function() {
			me._resizeWindow();
		};
		$(window).resize(function() {
			me._resizeWindow();
		});
	},
	
	_resizeWindow : function() {
		//header 与 footer 高度
		var headerHeight = $("#header").outerHeight();
		var footerHeight = $("#footer").outerHeight();
		//求屏幕的高度(先求网页高度,然后与页面实际显示高度比较, 选取长的为屏幕高度)
		var screenHeight = document.body.scrollHeight >  document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight;
		screenHeight = document.documentElement.scollHeight > screenHeight ? document.documentElement.scollHeight : screenHeight;
		//用屏幕高度减去头部和底部高度之和,求中间部分最小应该显示高度
		var minHeight = screenHeight - headerHeight - footerHeight;
		
		//求iframe 高度与 leftContent 高度,通过2者算出中间目前最低高度
		var iframeHeight = $("#iframe-zone").get(0).contentWindow.document.documentElement.scrollHeight;
		var leftContentHeight = $("#left-content").height();
		var middleZoneMaxHeight = iframeHeight > leftContentHeight ? iframeHeight : leftContentHeight;
		
		//求最小高度与最高高度之间的最大值
		var shouldHeight =  minHeight > middleZoneMaxHeight ? minHeight : middleZoneMaxHeight;
		$("#left-content").height(shouldHeight);
		$("#right-content").height(shouldHeight);
		$("#iframe-zone").height(shouldHeight)
	}
}


/*jquery-plugin*/
$.fn.moveShowAndHide = function(config) {
	if (!config || !config.direct || (!config.top && config.top != 0)) {
		return;
	}
	var $this = this, moveSize = 5, timer = 25,
		targetTop = config.top,
		direct = config.direct;
	
	if (direct == "show") {
		var show = function() {
			var top = parseInt($this.css("top"));
			if (top >= targetTop) {
				return;
			}
			top = top + moveSize > targetTop ? targetTop : top + moveSize;
			$this.css("top", top);
			setTimeout(function() {
				show();
			}, timer);
		}
		show();
	} else if (direct == "hide") {
		var hide = function() {
			var top = parseInt($this.css("top"));
			if (top <= targetTop) {
				return;
			}
			top = top - moveSize < targetTop ? targetTop : top - moveSize;
			$this.css("top", top);
			setTimeout(function() {
				hide();
			}, timer);
		}
		hide();
	}
}
